import React, { Component } from 'react'
import { Form, Input, Button} from 'antd';
import request from '../util/request'

export default class Registry extends Component {
    onFinish = values => {
        request.post('/api/login',{...values}).then(res => {
            if(res.code === 1){
                alert(res.msg);
                localStorage.setItem('token',res.token);
                localStorage.setItem('username',res.username);
                localStorage.setItem('rolename',res.rolename);
                this.props.history.push('/main');
            }else{
                alert(res.msg)
            }
        })
    };
    render() {
        return (
            <Form
              name="basic"
              initialValues={{ remember: true }}
              onFinish={this.onFinish}
              className="s-wrap"
            >
              <Form.Item
                label="学号"
                name="num"
                rules={[{ required: true, message: '请输入你的学号!' }]}
              >
                <Input />
              </Form.Item>
        
              <Form.Item
                label="密码"
                name="password"
                rules={[{ required: true, message: '请输入密码,密码为4到6位!',min:4,max:6 }]}
              >
                <Input.Password />
              </Form.Item>

              <Form.Item>
                <Button type="primary" htmlType="submit">
                  登录
                </Button>
              </Form.Item>
            </Form>
          );
    }
}





